import type { Ref } from "vue";
import type { RoleListResult } from "@/api/types";
import { ref } from "vue";

interface UseRoleAssignDrawer {
    /** 授权抽屉显隐 */
    assignVisible: Ref<boolean>;
    /** 当前角色 */
    currentRole: Ref<RoleListResult | null>;
    /** 打开授权抽屉 */
    openAssignDrawer: (row: RoleListResult) => void;
}

/** 角色授权 */
export function useRoleAssignDrawer(): UseRoleAssignDrawer {
    const assignVisible = ref(false);
    const currentRole = ref<RoleListResult | null>(null);

    function openAssignDrawer(row: RoleListResult): void {
        currentRole.value = row;
        assignVisible.value = true;
    }

    return {
        assignVisible,
        currentRole,
        openAssignDrawer,
    };
}
